package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.pojo.AdChannel;
import com.itheima.common.vo.PageResultVo;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.mapper.AdChannelMapper;
import com.itheima.admin.service.AdChannelService;
import org.springframework.stereotype.Service;

@Service
public class AdChannelServiceImpl extends ServiceImpl<AdChannelMapper, AdChannel> implements AdChannelService {

    /**
     * 频道分页查询
     *
     * @param dto
     * @return
     */
    @Override
    public PageResultVo list(ChannelPageRequestDto dto) {

        //1 设置分页参数
        IPage<AdChannel> pageInfo = new Page<>(dto.getPage(), dto.getSize());

        //2 查询条件
        LambdaQueryWrapper<AdChannel> lqw = new LambdaQueryWrapper<>();

        //2.1 按名称模糊查询
        lqw.like(StringUtils.isNotEmpty(dto.getName()), AdChannel::getName, dto.getName());

        //2.2 按status查询
        lqw.eq(null != dto.getStatus(),AdChannel::getStatus,dto.getStatus());

        //3 分页查询
        page(pageInfo, lqw);

        //4 构建PageResultVo返回
        PageResultVo<AdChannel> adChannelPageResultVo = PageResultVo.pageResult(dto.getPage(), dto.getSize(), pageInfo.getTotal(), pageInfo.getRecords());

        return adChannelPageResultVo ;
    }


}
